package com.gxa.controller.ly.drugManagement;

import com.gxa.common.R;
import com.gxa.common.vo.DrugNumRecordVo;
import com.gxa.entity.SysDrug;
import com.gxa.service.DrugManagementService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;

@Controller
@Api(value = "药品管理",tags = "药品管理接口API")
@RequestMapping("/drugManagement/drugManagement")
@RequiresRoles(value = {"超级管理员","院长","主任","秘书"},logical = Logical.OR)
public class DrugManagementController {

    @Autowired
    DrugManagementService drugManagementService;

    /**
     * 查找所有药品
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findDrugList",method = RequestMethod.GET)
    @ApiOperation(value = "查找所有药品接口",notes = "",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页页数", paramType = "query", dataType = "String", required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findDrugList(Integer currentPage,Integer pageSize){
        return drugManagementService.findDrugList(currentPage, pageSize);
    }

    /**
     * 通过药品id查询药品信息
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findDrugById",method = RequestMethod.POST)
    @ApiOperation(value = "查找药品接口",notes = "",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "当前页", paramType = "query", dataType = "String", required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findDrugById(@ApiParam(name = "id",value = "药品id") Integer id){
        return drugManagementService.findDrugById(id);
    }


    /**
     * 获取供应商名称通过供应商id
     * @param providerId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/chooseProvider",method = RequestMethod.GET)
    @ApiOperation(value = "选择供应商接口",notes = "选择供应商",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "providerId", value = "供应商ID", paramType = "query", dataType = "String", required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R chooseProvider(@RequestParam Integer providerId){
        return drugManagementService.chooseProvider(providerId);
    }

    /***
     * 添加一种药品
     * @param sysDrug
     * @return
     */
    @RequestMapping(value = "/addDrug",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加药品接口",notes = "添加药品",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addDrug(@RequestBody @ApiParam(name = "sysDrug",value = "药品对象",required = true) SysDrug sysDrug){
        return drugManagementService.addDrug(sysDrug);
    }
    @RequestMapping(value = "/addDrugImg",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加药品接口",notes = "添加药品",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "图片", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "id", value = "药品ID", paramType = "query", dataType = "String", required = true)
    })
    public R addDrugImg(@RequestParam("file") MultipartFile file,@RequestParam("id") Integer id,HttpServletRequest request){
        return drugManagementService.addDrugImg(file,id,request);
    }

    @RequestMapping(value = "/delDrug",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除药品接口",notes = "删除药品",httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "id",value = "药品",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R delDrug(@ApiParam(name = "id",value = "药品id") Integer id){

        return drugManagementService.deleteDrug(id);
    }

    /***
     * 修改药品
     * @param sysDrug
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateDrug",method = RequestMethod.POST)
    @ApiOperation(value = "修改药品信息",notes = "修改药品信息",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateDrugById(@RequestBody @ApiParam(name = "sysDrug",value = "药品对象",required = true) SysDrug sysDrug){
        return drugManagementService.updateDrug(sysDrug);
    }

    @ResponseBody
    @RequestMapping(value = "/updateDrugNum",method = RequestMethod.POST)
    @ApiOperation(value = "修改药品库存",notes = "修改药品库存",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateDrugNum(@RequestBody @ApiParam(name = "numRecordVo",value = "药品对象",required = true) DrugNumRecordVo numRecordVo,
                           HttpServletRequest request){
        return drugManagementService.updateDrugNum(numRecordVo,request);
    }

    @ResponseBody
    @RequestMapping(value = "/findDrugByCondition",method = RequestMethod.POST)
    @ApiOperation(value = "查找所有药品接口",notes = "",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每一页页数", paramType = "query", dataType = "String", required = true),
            @ApiImplicitParam(name = "condition", value = "条件", paramType = "query", dataType = "String", required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findDrugByCondition(Integer currentPage,Integer pageSize,String condition){
        return drugManagementService.findDrugByCondition(currentPage, pageSize,condition);
    }

}
